﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using Telerik.Windows.Controls;
using Telerik.Windows.Zip;
using System.IO;
using System.Windows.Controls.Primitives;

namespace Sample
{
  /// <summary>
  /// Interaction logic for WinRadControl.xaml
  /// </summary>
  public partial class WinRadControl : Window
  {
    private List<ObjDemo> m_ListDemo = null;
    private bool isBusy;
    private string busyContent;

    public List<ObjDemo> ListDemo
    {
      get { return m_ListDemo; }
      set { m_ListDemo = value; }
    }
    
    public WinRadControl()
    {
      InitializeComponent();
      this.DataContext = this;
      Telerik.Windows.Controls.GridViewCheckBoxColumn col = new Telerik.Windows.Controls.GridViewCheckBoxColumn();
      col.Name = "Checked";
      col.Header = "Checked";
      col.UniqueName = "Checked";
      col.EditTriggers = Telerik.Windows.Controls.GridView.GridViewEditTriggers.CellClick;
      col.AutoSelectOnEdit = true;
      dgvDemo.Columns.Add(col);
                  
      m_ListDemo = new List<ObjDemo>();
      m_ListDemo.Add(new ObjDemo(true,"First", "Info1"));
      m_ListDemo.Add(new ObjDemo(false,"Second", "Info2"));
      m_ListDemo.Add(new ObjDemo(true,"Third", "Info3"));
      for (int i = 0; i < 100; i++)
      {
        m_ListDemo.Add(new ObjDemo(true,"Third", "Info3"));
      }
    }

    private void Load_Click(object sender, RoutedEventArgs e)
    {
      int nbrRow = Convert.ToInt32(nudNbrRow.Value);
      for (int i = 0; i < nbrRow; i++)
			{
        m_ListDemo.Add(new ObjDemo(true,"Obj" + i, "Info " + i));
			}
      dgvDemo.Rebind();
    }

    private void Test_Click(object sender, RoutedEventArgs e)
    {
      //var selectedNode = tvDemo.SelectedItems;
      m_ListDemo.Add(new ObjDemo(true, "Obj", "Info "));
      
    }

    private void Zip_Click(object sender, RoutedEventArgs e)
    {
    }

    private void Wait_Click(object sender, RoutedEventArgs e)
    {
    }

    private ScrollBar FoundScrollBarByDependency(DependencyObject _CtrlParent)
    {
      ScrollBar found = null;

      //Niveau CheckBox ?
      ScrollBar scrollElem = _CtrlParent as ScrollBar;
      if (scrollElem != null && scrollElem.Orientation == Orientation.Vertical)
      {
        found = scrollElem;
      }
      
      //Si non --> On recherche dans ces enfants
      if (found == null)
      {
        if (_CtrlParent is Visual)
        {
          //Search
          for (int i = 0; i < VisualTreeHelper.GetChildrenCount(_CtrlParent); i++)
          {
            DependencyObject child = VisualTreeHelper.GetChild(_CtrlParent, i);
            if (child != null)
            {
              found = FoundScrollBarByDependency(child);
              if (found != null)
              {
                break;
              }
            }
          }
        }
      }

      return found;
    }

  }
}
